﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Common.Web.Share
{
    public sealed class RouteHander : IRouteHandler
    {
        private RouteHander()
        {
        }
        private static RouteHander instant = null;
        public static RouteHander Instant
        {
            get
            {
                if (instant == null) instant = new RouteHander();
                return instant;
            }
        }

        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {

            // Get route data values
            var routeData = requestContext.RouteData;
            var action = routeData.GetRequiredString("action");
            var controller = routeData.GetRequiredString("controller");

            // Lets do something with the requestContext.
            string actionName = action.Replace('-', '_');
            string controllerName = controller.Replace('-', '_');
            requestContext.RouteData.Values["action"] = actionName;
            requestContext.RouteData.Values["controller"] = controllerName;

            return new MvcHandler(requestContext);
        }
    }
}
